package com.example.enterprisemanager.mvvm.fragment.manager;

import android.app.Application;
import android.arch.lifecycle.MutableLiveData;
import android.support.annotation.NonNull;

import com.example.enterprisemanager.base.BaseModel;
import com.example.enterprisemanager.base.BaseViewModel;
import com.example.enterprisemanager.binding.BindingCommand;
import com.example.enterprisemanager.mvvm.ben.User;
import com.example.enterprisemanager.util.ToastUtil;

import cn.bmob.v3.BmobUser;

public class ManagerViewModel extends BaseViewModel<ManagerModel> {
    public BindingCommand inputCommand;
    public BindingCommand enrollCommand;
    public BindingCommand ruinCommand;

    public MutableLiveData<Integer> startFrag;

    public ManagerViewModel(@NonNull Application application) {
        super(application, new ManagerModel());
        init();
    }

    private void init() {
        startFrag = new MutableLiveData<>();

        inputCommand = new BindingCommand(() -> {
            if (!BmobUser.isLogin()) {
                ToastUtil.show(getApplication(), "请先登录");
                return;
            }
            startFrag.postValue(0);
        });
        enrollCommand = new BindingCommand(() -> {
            if (!BmobUser.isLogin()) {
                ToastUtil.show(getApplication(), "请先登录");
                return;
            }
            startFrag.postValue(1);
        });
        ruinCommand = new BindingCommand(() -> {
            if (!BmobUser.isLogin()) {
                ToastUtil.show(getApplication(), "请先登录");
                return;
            }
            startFrag.postValue(2);
        });
    }

    @Override
    public void onCreate() {
        super.onCreate();


    }

    public void isGet() {
        if (BmobUser.isLogin()) {
            User user = BmobUser.getCurrentUser(User.class);
            String username = (String) BmobUser.getObjectByKey("username");
            Integer age = (Integer) BmobUser.getObjectByKey("age");
        } else {
        }
    }
}
